API Documentation
Public Member Functions | List of all members
nkGraphics::Shader Class Reference

A shader class, feeding data to a Program. More...

Inheritance diagram for nkGraphics::Shader:
nkGraphics::Resource nkExport::Exportable

Public Member Functions

 Shader ()
 
virtual ~Shader ()
 
unsigned int getId () const
 
bool isUsableScene () const
 
bool isUsablePostProcess () const
 
bool isUsableCompute () const
 
bool isUsableGeometry () const
 
bool isUsableRaytracing () const
 
ProgramgetAttachedShaderProgram () const
 
unsigned int getMaxInstancePerBuffer () const
 
bool getDirtyInstanceData () const
 
virtual void setAttachedShaderProgram (Program *prog)
 
void setId (unsigned int id)
 
virtual void setMaxInstancePerBuffer (unsigned int value)
 
void setDirtyInstanceData (bool value)
 
virtual bool load () override
 
virtual void unload () override
 
ConstantBufferaddConstantBuffer (unsigned int registerSlot, unsigned int space=0)
 
ConstantBuffergetConstantBuffer (unsigned int slot, unsigned int space=0) const
 
void changeConstantBufferSlot (unsigned int fromSlot, unsigned int toSlot, unsigned int space=0)
 
void changeConstantBufferSpace (unsigned int fromSpace, unsigned int toSpace, unsigned int slot)
 
void deleteConstantBuffer (unsigned int slot, unsigned int space=0)
 
const ConstantBufferResourceDescgetConstantBufferPerIndex (unsigned int index) const
 
void addTexture (ShaderResource *texOrUav, unsigned int registerSlot, unsigned int space=0)
 
ShaderResourcegetTexture (unsigned int slot, unsigned int space=0) const
 
void setTexture (ShaderResource *texOrUav, unsigned int slot, unsigned int space=0)
 
void changeTextureSlot (unsigned int fromSlot, unsigned int toSlot, unsigned int space=0)
 
void changeTextureSpace (unsigned int fromSpace, unsigned int toSpace, unsigned int slot)
 
void forgetTexture (unsigned int slot, unsigned int space=0)
 
const ShaderResourceDescgetTexturePerIndex (unsigned int index) const
 
void addSampler (Sampler *sampler, unsigned int registerSlot, unsigned int space=0)
 
SamplergetSampler (unsigned int slot, unsigned int space=0) const
 
void setSampler (Sampler *sampler, unsigned int slot, unsigned int space=0)
 
void changeSamplerSlot (unsigned int fromSlot, unsigned int toSlot, unsigned int space=0)
 
void changeSamplerSpace (unsigned int fromSpace, unsigned int toSpace, unsigned int slot=0)
 
void forgetSampler (unsigned int slot, unsigned int space=0)
 
const SamplerResourceDescgetSamplerPerIndex (unsigned int index) const
 
void addUavBuffer (Buffer *buffer, unsigned int registerSlot, unsigned int space=0)
 
BuffergetUavBuffer (unsigned int slot, unsigned int space=0) const
 
void setUavBuffer (Buffer *buffer, unsigned int slot, unsigned int space=0)
 
void changeUavBufferSlot (unsigned int fromSlot, unsigned int toSlot, unsigned int space=0)
 
void changeUavBufferSpace (unsigned int fromSpace, unsigned int toSpace, unsigned int slot=0)
 
void forgetUavBuffer (unsigned int slot, unsigned int space=0)
 
const UavResourceDescgetUavBufferPerIndex (unsigned int index) const
 
virtual ShaderInstanceMemorySlotaddInstanceMemorySlot ()
 
virtual ShaderInstanceMemorySlotgetInstanceMemorySlot (unsigned int index)
 
virtual ShaderInstanceMemorySlotgetInstanceMemorySlotReadOnly (unsigned int index) const
 
virtual void changeInstanceMemorySlotOrder (unsigned int fromIndex, unsigned int toIndex)
 
virtual void deleteInstanceMemorySlot (unsigned int index)
 
virtual void exportClassToTree (nkExport::Node *rootNode) override
 
virtual void importClassFromTree (nkExport::Node *rootNode) override
 
- Public Member Functions inherited from nkGraphics::Resource
 Resource ()
 
 Resource (const char *path)
 
virtual ~Resource ()
 
bool isReadyForRendering () const
 
bool isUnloaded () const
 
RESOURCE_LOAD_STATE getLoadState () const
 
std::string_view getResourcePath () const
 
RESOURCE_TYPE getResourceTypeName () const
 
std::string_view getResourceName () const
 
bool getHidden () const
 
virtual void setResourcePath (const std::string_view &path)
 
void setResourceName (const std::string_view &name)
 
void setHidden (bool value)
 
- Public Member Functions inherited from nkExport::Exportable
 Exportable ()
 
virtual ~Exportable ()
 

Detailed Description

A shader class, feeding data to a Program.

The Shader class is describing all the resources to bind to a Program during rendering.

Constructor & Destructor Documentation

◆ Shader()

nkGraphics::Shader::Shader ( )

Constructor. See ShaderManager::createOrRetrieveShader().

◆ ~Shader()

virtual nkGraphics::Shader::~Shader ( )
virtual

Destructor.

Member Function Documentation

◆ getId()

unsigned int nkGraphics::Shader::getId ( ) const
Returns
The id of the shader.

◆ isUsableScene()

bool nkGraphics::Shader::isUsableScene ( ) const
Returns
If the shader is usable for rendering a scene.

◆ isUsablePostProcess()

bool nkGraphics::Shader::isUsablePostProcess ( ) const
Returns
If the shader is usable for post processing.

◆ isUsableCompute()

bool nkGraphics::Shader::isUsableCompute ( ) const
Returns
If the shader is usable for compute.

◆ isUsableGeometry()

bool nkGraphics::Shader::isUsableGeometry ( ) const
Returns
If the shader is usable for geometry streaming.

◆ isUsableRaytracing()

bool nkGraphics::Shader::isUsableRaytracing ( ) const
Returns
If the shader is usable for raytracing.

◆ getAttachedShaderProgram()

Program* nkGraphics::Shader::getAttachedShaderProgram ( ) const
Returns
The attached program.

◆ getMaxInstancePerBuffer()

unsigned int nkGraphics::Shader::getMaxInstancePerBuffer ( ) const
Returns
The maximum number of instance per instance buffers.

◆ getDirtyInstanceData()

bool nkGraphics::Shader::getDirtyInstanceData ( ) const
Returns
If the instance data has been dirtified.

◆ setAttachedShaderProgram()

virtual void nkGraphics::Shader::setAttachedShaderProgram ( Program prog)
virtual
Parameters
progThe program to attach to the shader.

◆ setId()

void nkGraphics::Shader::setId ( unsigned int  id)
Parameters
idThe id to attach to the shader. Should not be called by external code.

◆ setMaxInstancePerBuffer()

virtual void nkGraphics::Shader::setMaxInstancePerBuffer ( unsigned int  value)
virtual
Parameters
valueThe maximum instance count allowed per instance buffer.
Remarks
Too few instances per buffer can cause multiple buffer allocations during rendering to fill for all instances required. Too many instances per buffer will cause memory wasting as the buffer is never filled up. Try finding the balance, depending on the scene rendered.

◆ setDirtyInstanceData()

void nkGraphics::Shader::setDirtyInstanceData ( bool  value)
Parameters
valueWhether the instance data should be flagged as dirty or not.
Remarks
Dirtification will cause the instance related tracking data to be updated. In theory, should not be called by external code.

◆ load()

virtual bool nkGraphics::Shader::load ( )
overridevirtual

Initializes the shader and make it ready for rendering.

Returns
If the initialization went well (true) or not (false).

Implements nkGraphics::Resource.

◆ unload()

virtual void nkGraphics::Shader::unload ( )
overridevirtual

Unloads and frees all internal memory of the shader.

Implements nkGraphics::Resource.

◆ addConstantBuffer()

ConstantBuffer* nkGraphics::Shader::addConstantBuffer ( unsigned int  registerSlot,
unsigned int  space = 0 
)

Adds a constant buffer to the data fed to the program.

Parameters
registerSlotThe register slot the resource is attached to.
spaceThe register space the resource is attached to.
Returns
The resource freshly created. The shader is responsible for the allocated memory, external code should not delete it. See deleteConstantBuffer().

◆ getConstantBuffer()

ConstantBuffer* nkGraphics::Shader::getConstantBuffer ( unsigned int  slot,
unsigned int  space = 0 
) const
Parameters
slotThe register slot the requested resource covers.
spaceThe register space the requested resource covers.
Returns
Requested resource if available, nullptr else.

◆ changeConstantBufferSlot()

void nkGraphics::Shader::changeConstantBufferSlot ( unsigned int  fromSlot,
unsigned int  toSlot,
unsigned int  space = 0 
)

Changes the slot a resource should be fed to.

Parameters
fromSlotThe slot the resource currently feeds.
toSlotThe slot to feed.
spaceThe register space the resource currently occupies.

◆ changeConstantBufferSpace()

void nkGraphics::Shader::changeConstantBufferSpace ( unsigned int  fromSpace,
unsigned int  toSpace,
unsigned int  slot 
)

Changes the space a resource should be fed to.

Parameters
fromSpaceThe register space the resource currently feeds.
toSpaceThe space to feed.
slotThe register slot the resource currently occupies.

◆ deleteConstantBuffer()

void nkGraphics::Shader::deleteConstantBuffer ( unsigned int  slot,
unsigned int  space = 0 
)

Removes a constant buffer from the feeding, and frees its memory.

Parameters
slotThe register slot used by the resource.
spaceThe register space used by the resource.

◆ getConstantBufferPerIndex()

const ConstantBufferResourceDesc* nkGraphics::Shader::getConstantBufferPerIndex ( unsigned int  index) const

Accesses a resource, by index. Note that an index can return different resources as the internal memory is changed. Mainly useful to loop over all the resources in one go.

Parameters
indexThe index of the resource wanted.
Returns
A description of the resource if available, nullptr else.

◆ addTexture()

void nkGraphics::Shader::addTexture ( ShaderResource texOrUav,
unsigned int  registerSlot,
unsigned int  space = 0 
)

Adds a texture or buffer to the data fed to the program.

Parameters
texOrUavThe resource to feed to the program.
registerSlotThe register slot the resource is attached to.
spaceThe register space the resource is attached to.

◆ getTexture()

ShaderResource* nkGraphics::Shader::getTexture ( unsigned int  slot,
unsigned int  space = 0 
) const
Parameters
slotThe register slot the requested resource covers.
spaceThe register space the requested resource covers.
Returns
Requested resource if available, nullptr else.

◆ setTexture()

void nkGraphics::Shader::setTexture ( ShaderResource texOrUav,
unsigned int  slot,
unsigned int  space = 0 
)

Changes the resource fed to a slot and space.

Parameters
texOrUavThe resource to feed.
slotThe currently used register slot.
spaceThe currently used space.

◆ changeTextureSlot()

void nkGraphics::Shader::changeTextureSlot ( unsigned int  fromSlot,
unsigned int  toSlot,
unsigned int  space = 0 
)

Changes the slot a resource should be fed to.

Parameters
fromSlotThe slot the resource currently feeds.
toSlotThe slot to feed.
spaceThe register space the resource currently occupies.

◆ changeTextureSpace()

void nkGraphics::Shader::changeTextureSpace ( unsigned int  fromSpace,
unsigned int  toSpace,
unsigned int  slot 
)

Changes the space a resource should be fed to.

Parameters
fromSpaceThe register space the resource currently feeds.
toSpaceThe space to feed.
slotThe register slot the resource currently occupies.

◆ forgetTexture()

void nkGraphics::Shader::forgetTexture ( unsigned int  slot,
unsigned int  space = 0 
)

Removes a resource from the feeding.

Parameters
slotThe register slot used by the resource.
spaceThe register space used by the resource.

◆ getTexturePerIndex()

const ShaderResourceDesc* nkGraphics::Shader::getTexturePerIndex ( unsigned int  index) const

Accesses a resource, by index. Note that an index can return different resources as the internal memory is changed. Mainly useful to loop over all the resources in one go.

Parameters
indexThe index of the resource wanted.
Returns
A description of the resource if available, nullptr else.

◆ addSampler()

void nkGraphics::Shader::addSampler ( Sampler sampler,
unsigned int  registerSlot,
unsigned int  space = 0 
)

Adds a sampler to the data fed to the program.

Parameters
samplerThe resource to feed to the program.
registerSlotThe register slot the resource is attached to.
spaceThe register space the resource is attached to.

◆ getSampler()

Sampler* nkGraphics::Shader::getSampler ( unsigned int  slot,
unsigned int  space = 0 
) const
Parameters
slotThe register slot the requested resource covers.
spaceThe register space the requested resource covers.
Returns
Requested resource if available, nullptr else.

◆ setSampler()

void nkGraphics::Shader::setSampler ( Sampler sampler,
unsigned int  slot,
unsigned int  space = 0 
)

Changes the resource fed to a slot and space.

Parameters
samplerThe resource to feed.
slotThe currently used register slot.
spaceThe currently used space.

◆ changeSamplerSlot()

void nkGraphics::Shader::changeSamplerSlot ( unsigned int  fromSlot,
unsigned int  toSlot,
unsigned int  space = 0 
)

Changes the slot a resource should be fed to.

Parameters
fromSlotThe slot the resource currently feeds.
toSlotThe slot to feed.
spaceThe register space the resource currently occupies.

◆ changeSamplerSpace()

void nkGraphics::Shader::changeSamplerSpace ( unsigned int  fromSpace,
unsigned int  toSpace,
unsigned int  slot = 0 
)

Changes the space a resource should be fed to.

Parameters
fromSpaceThe register space the resource currently feeds.
toSpaceThe space to feed.
slotThe register slot the resource currently occupies.

◆ forgetSampler()

void nkGraphics::Shader::forgetSampler ( unsigned int  slot,
unsigned int  space = 0 
)

Removes a resource from the feeding.

Parameters
slotThe register slot used by the resource.
spaceThe register space used by the resource.

◆ getSamplerPerIndex()

const SamplerResourceDesc* nkGraphics::Shader::getSamplerPerIndex ( unsigned int  index) const

Accesses a resource, by index. Note that an index can return different resources as the internal memory is changed. Mainly useful to loop over all the resources in one go.

Parameters
indexThe index of the resource wanted.
Returns
A description of the resource if available, nullptr else.

◆ addUavBuffer()

void nkGraphics::Shader::addUavBuffer ( Buffer buffer,
unsigned int  registerSlot,
unsigned int  space = 0 
)

Adds a uav buffer to the data fed to the program.

Parameters
bufferThe resource to feed to the program.
registerSlotThe register slot the resource is attached to.
spaceThe register space the resource is attached to.

◆ getUavBuffer()

Buffer* nkGraphics::Shader::getUavBuffer ( unsigned int  slot,
unsigned int  space = 0 
) const
Parameters
slotThe register slot the requested resource covers.
spaceThe register space the requested resource covers.
Returns
Requested resource if available, nullptr else.

◆ setUavBuffer()

void nkGraphics::Shader::setUavBuffer ( Buffer buffer,
unsigned int  slot,
unsigned int  space = 0 
)

Changes the resource fed to a slot and space.

Parameters
bufferThe resource to feed.
slotThe currently used register slot.
spaceThe currently used space.

◆ changeUavBufferSlot()

void nkGraphics::Shader::changeUavBufferSlot ( unsigned int  fromSlot,
unsigned int  toSlot,
unsigned int  space = 0 
)

Changes the slot a resource should be fed to.

Parameters
fromSlotThe slot the resource currently feeds.
toSlotThe slot to feed.
spaceThe register space the resource currently occupies.

◆ changeUavBufferSpace()

void nkGraphics::Shader::changeUavBufferSpace ( unsigned int  fromSpace,
unsigned int  toSpace,
unsigned int  slot = 0 
)

Changes the space a resource should be fed to.

Parameters
fromSpaceThe register space the resource currently feeds.
toSpaceThe space to feed.
slotThe register slot the resource currently occupies.

◆ forgetUavBuffer()

void nkGraphics::Shader::forgetUavBuffer ( unsigned int  slot,
unsigned int  space = 0 
)

Removes a resource from the feeding.

Parameters
slotThe register slot used by the resource.
spaceThe register space used by the resource.

◆ getUavBufferPerIndex()

const UavResourceDesc* nkGraphics::Shader::getUavBufferPerIndex ( unsigned int  index) const

Accesses a resource, by index. Note that an index can return different resources as the internal memory is changed. Mainly useful to loop over all the resources in one go.

Parameters
indexThe index of the resource wanted.
Returns
A description of the resource if available, nullptr else.

◆ addInstanceMemorySlot()

virtual ShaderInstanceMemorySlot* nkGraphics::Shader::addInstanceMemorySlot ( )
virtual

Adds an instance memory slot to the data feeding. Instance memory slots are fed sequentially, in the order they are declared. Be sure to align all structures.

Returns
A newly allocated slot. Shader is responsible for the memory, external code should not delete it. See deleteInstanceMemorySlot().

◆ getInstanceMemorySlot()

virtual ShaderInstanceMemorySlot* nkGraphics::Shader::getInstanceMemorySlot ( unsigned int  index)
virtual

Retrieves an existing instance memory slot.

Parameters
indexThe index of the slot to retrieve.
Returns
The slot requested if available, nullptr else.

◆ getInstanceMemorySlotReadOnly()

virtual ShaderInstanceMemorySlot* nkGraphics::Shader::getInstanceMemorySlotReadOnly ( unsigned int  index) const
virtual

Retrieves an existing instance memory slot, for read only operation. Use this function whenever possible as this won't dirtify the instance tracking data.

Parameters
indexThe index of the slot to retrieve.
Returns
The slot requested if available, nullptr else.

◆ changeInstanceMemorySlotOrder()

virtual void nkGraphics::Shader::changeInstanceMemorySlotOrder ( unsigned int  fromIndex,
unsigned int  toIndex 
)
virtual

Changes the ordering within the slots.

Parameters
fromIndexThe slot to move.
toIndexThe index to move the slot to.

◆ deleteInstanceMemorySlot()

virtual void nkGraphics::Shader::deleteInstanceMemorySlot ( unsigned int  index)
virtual

Erases and frees an instance memory slot.

Parameters
indexThe index of the slot to erase.

◆ exportClassToTree()

virtual void nkGraphics::Shader::exportClassToTree ( nkExport::Node rootNode)
overridevirtual

Basic exporting capabilities.

Parameters
rootNodeThe tree to export to.

Implements nkExport::Exportable.

◆ importClassFromTree()

virtual void nkGraphics::Shader::importClassFromTree ( nkExport::Node rootNode)
overridevirtual

Basic importing capabilities.

Parameters
rootNodeThe tree to import to.

Implements nkExport::Exportable.


The documentation for this class was generated from the following file: